﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace LongNet.Util
{
    public class InitInfo
    {
        /// <summary>
        /// 基础分类的Xml配置文件路径
        /// </summary>
        public readonly static string XmlPath = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["emunXml"].Trim());

        private static Dictionary<string, string> _costNumber = new Dictionary<string, string>();

        private static Dictionary<string, string> _HouseSource = new Dictionary<string, string>();
        /// <summary>
        /// 房屋来源（房屋取得方式）
        /// </summary>
        public static Dictionary<string, string> HouseSource
        {
            get
            {
                return _HouseSource;
            }
        }

        private static Dictionary<string, string> _HouseStruct = new Dictionary<string, string>();
        /// <summary>
        /// 房屋结构
        /// </summary>
        public static Dictionary<string, string> HouseStruct
        {
            get
            {
                return _HouseStruct;
            }
        }
        private static Dictionary<string, string> _HouseProperty = new Dictionary<string, string>();
        /// <summary>
        /// 房屋性质（项目类型）
        /// </summary>
        public static Dictionary<string, string> HouseProperty
        {
            get
            {
                return _HouseProperty;
            }
        }
        private static Dictionary<string, string> _HouseType = new Dictionary<string, string>();
        /// <summary>
        /// 房屋类型
        /// </summary>
        public static Dictionary<string, string> HouseType
        {
            get
            {
                return _HouseType;
            }
        }

        private static Dictionary<string, string> _HouseStyle = new Dictionary<string, string>();
        /// <summary>
        /// 房屋户型
        /// </summary>
        public static Dictionary<string, string> HouseStyle
        {
            get
            {
                return _HouseStyle;
            }
        }
        private static Dictionary<string, string> _HouseUse = new Dictionary<string, string>();
        /// <summary>
        /// 房屋用途
        /// </summary>
        public static Dictionary<string, string> HouseUse
        {
            get
            {
                return _HouseUse;
            }
        }


        private static Dictionary<string, string> _PlanUse = new Dictionary<string, string>();
        /// <summary>
        /// 规划用途
        /// </summary>
        public static Dictionary<string, string> PlanUse
        {
            get
            {
                return _PlanUse;
            }
        }

        private static Dictionary<string, string> _HouseCategory = new Dictionary<string, string>();
        /// <summary>
        /// 房屋分类
        /// </summary>
        public static Dictionary<string, string> HouseCategory
        {
            get
            {
                return _HouseCategory;
            }
        }

        private static Dictionary<string, string> _LandDescent = new Dictionary<string, string>();
        /// <summary>
        /// 土地出让方式
        /// </summary>
        public static Dictionary<string, string> LandDescent
        {
            get
            {
                return _LandDescent;
            }
        }

        private static Dictionary<string, string> _LandRight = new Dictionary<string, string>();
        /// <summary>
        /// 土地性质
        /// </summary>
        public static Dictionary<string, string> LandRight
        {
            get
            {
                return _LandRight;
            }
        }

        private static Dictionary<string, string> _RightOfOwner = new Dictionary<string, string>();
        /// <summary>
        /// 房屋权属性质
        /// </summary>
        public static Dictionary<string, string> RightOfOwner
        {
            get
            {
                return _RightOfOwner;
            }
        }

        private static Dictionary<string, string> _LandUseType = new Dictionary<string, string>();
        /// <summary>
        /// 土地使用方式
        /// </summary>
        public static Dictionary<string, string> LandUseType
        {
            get
            {
                return _LandUseType;
            }
        }

        private static Dictionary<string, string> _CertClass = new Dictionary<string, string>();
        /// <summary>
        /// 证件类别
        /// </summary>
        public static Dictionary<string, string> CertClass
        {
            get { return InitInfo._CertClass; }
            set { InitInfo._CertClass = value; }
        }

        private static Dictionary<string, string> _PactType = new Dictionary<string, string>();
        /// <summary>
        /// 证件类别
        /// </summary>
        public static Dictionary<string, string> PactType
        {
            get { return InitInfo._PactType; }
            set { InitInfo._PactType = value; }
        }

        private static Dictionary<string, string> _SeizureNatrue = new Dictionary<string, string>();
        /// <summary>
        /// 查封性质
        /// </summary>
        public static Dictionary<string, string> SeizureNatrue
        {
            get
            {
                return _SeizureNatrue;
            }
        }

        private static Dictionary<string, string> _ArchivesType = new Dictionary<string, string>();
        /// <summary>
        /// 档案类型
        /// </summary>
        public static Dictionary<string, string> ArchivesType
        {
            get
            {
                return _ArchivesType;
            }
        }

        private static Dictionary<string, string> _FillMindItem = new Dictionary<string, string>();

        /// <summary>
        /// 审批意见
        /// </summary>
        public static Dictionary<string, string> FillMindItem
        {
            get
            {
                return _FillMindItem;
            }
        }

        /// <summary>
        /// 分页页面大小
        /// </summary>
        public static int PageSize
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["PageSize"] == null ? 12 : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PageSize"]);
            }
        }

        /// <summary>
        /// 初始化变量
        /// </summary>
        public static void Init()
        {
            InitBasicDic();
        }

        /// <summary>
        /// 初始化基础数据字典
        /// </summary>
        private static void InitBasicDic()
        {
            try
            {
                _HouseSource = PublicClass.GetCategoryFromXml("DIC_BUILDING_DESCENT");  //房屋来源

                _HouseStruct = PublicClass.GetCategoryFromXml("DIC_BUILDING_MATER");    //房屋结构

                _HouseProperty = PublicClass.GetCategoryFromXml("GetProjectType");    //房屋性质（项目类型）

                _HouseType = PublicClass.GetCategoryFromXml("DIC_BUILDING_Type");    //房屋类型

                _HouseStyle = PublicClass.GetCategoryFromXml("DIC_FLAT_STYLE"); //房屋户型

                _HouseCategory = PublicClass.GetCategoryFromXml("DIC_FLAT_TYPE");   //房屋分类

                _HouseUse = PublicClass.GetCategoryFromXml("DIC_HOUSEUSE");    //房屋用途

                _LandDescent = PublicClass.GetCategoryFromXml("DIC_LAND_DESCENT");    //土地出让方式

                _LandRight = PublicClass.GetCategoryFromXml("DIC_LAND_RIGHT");  //土地性质

                _RightOfOwner = PublicClass.GetCategoryFromXml("DIC_RIGHT_OF_OWNER");  //房屋权属性质

                //  _LandUseType = PublicClass.GetCategoryFromXml("DIC_ydfs");    //用地方式

                _PlanUse = PublicClass.GetCategoryFromXml("DIC_LAND_USE");   //规划用途

                _SeizureNatrue = PublicClass.GetCategoryFromXml("SeizureNatrue");   //查封性质 

                _CertClass = PublicClass.GetCategoryFromXml("CertClass");   //证件类别 

                _PactType = PublicClass.GetCategoryFromXml("PactType");   //合同类型 

                _costNumber = PublicClass.GetCategoryFromXml("CostNumber");//发票类型

                _ArchivesType = PublicClass.GetCategoryFromXml("ArchivesType");//档案类型

                _FillMindItem = PublicClass.GetCategoryFromXml("MindItems");//审批意见

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 获取Xml配置中的基础信息键值对
        /// </summary>
        /// <param name="Key"></param>
        /// <returns></returns>
        public static Dictionary<string, string> GetCategoryFromXml(string Key)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            try
            {
                System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

                xmlDoc.Load(InitInfo.XmlPath);

                System.Xml.XmlNodeList xnodlist = xmlDoc.SelectNodes("combos");

                System.Xml.XmlNode xmlNode = xnodlist[0].SelectSingleNode("combo[@id=\"" + Key + "\"]");

                if (xmlNode.Attributes["type"].Value == "TABLE")
                {
                    throw new Exception("该方法不支持从数据库中读取！");
                }
                if (xmlNode.Attributes["type"].Value == "CODE")
                {
                    xnodlist = xmlNode.ChildNodes;

                    foreach (System.Xml.XmlNode childNode in xmlNode.ChildNodes)
                    {
                        dic.Add(childNode.Attributes["value"].Value, childNode.InnerText);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

            }
            return dic;
        }



    }
}